home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr48 / pas_0593.zip / SVGA-ASM.PAS < prev    next >
Pascal/Delphi Source File  |  1993-05-30  |  4KB  |  186 lines

  1. {─ Fido Pascal Conference ────────────────────────────────────────────── PASCAL ─
  2. Msg  : 250 of 346                                                               
  3. From : Alexander Christov                  2:341/34.0           23 Apr 93  12:58 
  4. To   : Marc Van Leeuwen                    2:234/10.0                            
  5. Subj : S-VGA Programming...                                                   
  6. ────────────────────────────────────────────────────────────────────────────────
  7. Hi Marc!
  8.  
  9. Keld R. Hansen decia a Marc Van Leeuwen:
  10.  
  11.  
  12.  KRH> In a message dated 08 May 93, Marc Van Leeuwen (2:292/405.0) wrote:
  13.  
  14.  >> I desperatly need a module to write SVGA -WITH SOURCE!- screens.  I
  15.  >> have to make a map on-screen, but all I managed is using SegA000
  16.  >> for mode #13.
  17.  
  18.  KRH> What chip-set are you using?
  19.  
  20.  I suggest you to get UVESA.* (UNIVESA.EXE) which is a universal VESA driver for
  21. many chipsets and write only VESA compatible programs. It is not very slow if
  22. you use VESA only to change the bank number. The "only" difference between mode
  23. $13 and "bigger" modes is that the memory required for a single screen is bigger
  24. than 64K, so a paging scheme is used to map a region of the card's video memory
  25. into the main memory. If you use banks of 64K, it is very easy to check if it is
  26. necessary to change the bank after an operation. Suppose you have in DI a screen
  27. offset. If you INC DI and it becomes zero OR if you ADD to DI and afterwards
  28. CF=1, you must increment the current bank number.
  29.  To get the address of a pixel you can use this:}
  30.  
  31. Procedure SVGAAddr;Assembler;
  32. { Input:
  33.          DI <- X
  34.          AX <- Y
  35.          Linelength = length of a line in pixels (640,800,etc)
  36.  
  37.   Output:
  38.  
  39.          DI <- Offest
  40.          Bank changed accordingly
  41.  
  42.   DX,BX Destroyed
  43.  
  44.  
  45. }
  46. ASM
  47.  MOV BX,LineLength
  48.  MUL BX
  49.  ADD DI,AX              { DI = LineLength*Y+X justified to segment boundary }
  50.  ADC DX,0
  51.  MOV AX,DX              { Check page number }
  52.  CALL SetRWBank { Select bank for reading/writing }
  53. @Finish:
  54. END;
  55.  
  56. And as an example, look at this code that draws horizontal and vertical lines on
  57. a SVGA.
  58.  
  59. Procedure _SVGA.HLine(X1,X2,Y:Word);Assembler;
  60. ASM
  61.  MOV AX,X1
  62.  CMP AX,X2              { If X1>X2, exchange them }
  63.  JA @XChg
  64. @LX:
  65.  MOV DI,X1
  66.  MOV AX,Y
  67.  CALL SVGAAddr
  68.  MOV AX,SegA000
  69.  MOV ES,AX
  70.  MOV CX,X2
  71.  SUB CX,X1
  72.  INC CX                 { CX = line length in pixels }
  73.  
  74.  MOV DX,LineStyle       { A WORD pattern, just like BGI's linestyle }
  75.  
  76.  MOV AX,DI              { Test if any bank switching will be necessary }
  77.  ADD AX,CX
  78.  JNC @Fast              { Nope? Jump to fast routine }
  79.  
  80. @WPix:
  81.  MOV AL,CurFG           { Drawing color }
  82.  ROL DX,1               { Get current style bit into CF }
  83.  JC @Write1             { If set, plot a foreground color pixel, otherwise a }
  84.  MOV AL,CurBG           { background color pixel }
  85. @Write1:
  86.  MOV ES:[DI],AL         { Plot }
  87.  INC DI                 { Next point }
  88.  JZ @L0
  89.  LOOP @WPix
  90.  JMP @End
  91. @L0:
  92.  CALL IncRWBank         { This routines increments the current bank }
  93.  LOOP @WPix
  94.  JMP @End
  95. @XChg:
  96.  MOV BX,X2
  97.  MOV X2,AX
  98.  MOV X1,BX
  99.  JMP @LX
  100. @Fast:           { No bank switching necessary }
  101.  MOV AH,CurFG
  102.  MOV AL,AH
  103.  SHR CX,1        { Word align }
  104.  JC @OnePix
  105.  REP STOSW       { That's it }
  106.  JMP @End
  107.  
  108. @OnePix:
  109.  STOSB
  110.  REP STOSW
  111.  
  112. @End:
  113.  MOV AX,X2
  114.  MOV CurX,AX
  115.  MOV AX,Y
  116.  MOV CurY,AX
  117. END;
  118.  
  119. Procedure _SVGA.VLine(Y1,Y2,X:Word);Assembler;
  120. ASM
  121.  MOV DI,Y1
  122.  CMP DI,Y2
  123.  JA @XChg
  124. @L0:
  125.  MOV AX,Y1
  126.  MOV DI,X
  127.  CALL SVGAAddr
  128.  MOV AX,SegA000
  129.  MOV ES,AX
  130.  MOV CX,Y2
  131.  SUB CX,Y1
  132.  INC CX
  133.  MOV DX,LineStyle
  134. @Loop:
  135.  MOV AL,CurFG
  136.  ROL DX,1
  137.  JC @Write
  138.  MOV AL,CurBG
  139. @Write:
  140.  MOV ES:[DI],AL
  141.  ROL DX,1
  142.  ADD DI,LineLength
  143.  JC @IncBank
  144. @L1:
  145.  LOOP @Loop
  146.  MOV AX,X
  147.  MOV CurX,AX
  148.  MOV AX,Y2
  149.  MOV CurY,AX
  150.  JMP @End
  151. @XChg:
  152.  MOV AX,Y2
  153.  MOV Y1,AX
  154.  MOV Y2,DI
  155.  MOV DI,Y1
  156.  JMP @L0
  157. @IncBank:
  158.  CALL IncRWBank
  159.  JMP @L1
  160. @End:
  161. END;
  162.  
  163. And this proc clears the screen
  164.  
  165. Procedure _SVGA.ClrScr;Assembler;
  166. ASM
  167.  XOR AX,AX
  168.  CALL SetRWBank
  169.  MOV AX,SegA000
  170.  MOV ES,AX
  171.  MOV BX,5
  172. @BankLoop:
  173.  MOV AX,BX
  174.  DEC AX
  175.  CALL SetRWBank
  176.  MOV AL,CurBG
  177.  MOV AH,AL
  178.  MOV CX,32768
  179.  REP STOSW   { Or MOV CX,32768/2, then DB $66 (I think) REP STOSW, for 386 }
  180.  DEC BX
  181.  JNZ @BankLoop
  182. END;
  183.  
  184.  
  185. To set/change the bank, simply call INT 10h with AX=$4F05 and DX=<bank number>
  186. Remember that this code works only with 64k banks.